var api = require('./utils/util.js').default;
App({
  // 小程序初始化
  onLaunch: function () {
    var self = this;
    wx.login({
      success(res) {
        if (res.code) {
          var data = {
            code: res.code
          }
          api.app_login(data).then(res => {
            self.globalData.is_visitor = res.data.is_visitor;
            self.globalData.is_defined = res.data.is_defined;
            self.globalData.is_rider = res.data.is_rider;
            self.globalData.openid = res.data.openid;
            self.globalData.sessionkey = res.data.session_key;
            self.globalData.school_num = res.data.school_num;
            var name = res.data.nickname;
            if (name.length > 7) {
              self.globalData.user_name = name.substr(res.data.nickname, 6) + '…'
            } else {
              self.globalData.user_name = name;
            }
            self.globalData.user_img = res.data.img_src;
            self.globalData.user_pho = res.data.pho_num;
            console.log("globaldata：")
            console.log(self.globalData);
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
  },

  globalData: {
    is_visitor: true, // 游客标记
    is_defined: false, // 获取手机号实名认证
    is_rider: false, // 是否有骑手资质
    openid: null, // 用户openid
    rider_is_working: false, //骑手工作状态
    user_name: null, //用户名
    user_img: null, //用户头像
    user_pho: null, //手机号标识
    school_num: null, //学号
    sessionkey: null,
  }

})